home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 3 / CU Amiga Magazine's Super CD-ROM 03 (1996)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1996-09].iso / misc / readers_utils / aslplaysound / soundplayer.s < prev    next >
Text File  |  1992-09-02  |  6KB  |  316 lines

  1. *Sound Play
  2. *By Mark Retallack
  3.  
  4. * ensure case dependent and debug
  5.     opt    c+,d+
  6.  
  7. * firstly get the required constants and macros
  8.  
  9.     
  10.     include dos/dos_lib.i            include dos commands
  11.     include dos/dos.i            include dos workings
  12.     include    exec/exec_lib.i
  13.  
  14. * setup library offsets
  15.  
  16. FSGetSize    EQU    -30
  17. FSLoadSound    EQU    -36
  18. FSPlaySound    EQU    -42
  19. FSStopSound    EQU    -48
  20.  
  21.  
  22. CALLFU    MACRO
  23.     move.l    _futurebase,a6
  24.     jsr    FS\1(a6)
  25.     ENDM
  26.  
  27.  
  28. * firstly open the Future library
  29.     lea    funame(pc),a1            store funame in a1
  30.     moveq    #0,d0                dont care which version
  31.     CALLEXEC OpenLibrary
  32.     tst.l    d0                test d0 and set flag z if lib was opened
  33.     beq    gofast                if flag z is not set goto goawayfast
  34.     move.l    d0,_futurebase            store lib pointer
  35.  
  36.  
  37. *open dos library
  38.  
  39.     lea    dosname(pc),a1            store dosname in a1
  40.     moveq    #0,d0                dont care which version
  41.     CALLEXEC OpenLibrary
  42.     tst.l    d0                test d0 and set flag z if lib was opened
  43.     beq    goclosefu            if flag z is not set goto goawayfast
  44.     move.l    d0,_DOSBase            store lib pointer
  45.         
  46.         
  47. *set handle    
  48.     
  49.     CALLDOS    Output                Call output
  50.     move.l    d0,_stdout            Move address to stdout
  51.  
  52.     CALLDOS    Input
  53.     move.l    d0,_stdin
  54.     
  55. *write to dos
  56.          
  57.     move.l    _stdout,d1            DOS output file handle         
  58.     move.l    #messa,d2            start of message          
  59.     move.l    #sizeofmessa,d3            size of message   
  60.         CALLDOS    Write                DOS call to write message
  61.          
  62.                  
  63. flab    move.l    _stdout,d1            DOS output file handle         
  64.     move.l    #messg,d2            start of message          
  65.     move.l    #sizeofmessg,d3            size of message   
  66.         CALLDOS    Write                DOS call to write message
  67.                   
  68. *Read Name of file
  69.  
  70.     move.l    _stdin,d1
  71.     move.l    #messb,d2
  72.     move.l    #40,d3
  73.     CALLDOS    Read    
  74.          
  75.     lea    messb,a0
  76.     subi    #1,d0
  77.     move.l    d0,d7      
  78.     move.l    #0,(a0,d0)
  79.                   
  80.                               
  81. *get the size of the file
  82.     
  83.     lea    messb,a0    
  84.                      
  85.     CALLFU    GetSize
  86.         
  87.     tst.l    d0
  88.     bne    pass
  89.     
  90.     move.l    _stdout,d1            DOS output file handle         
  91.     move.l    #messj,d2            start of message          
  92.     move.l    #sizeofmessj,d3            size of message   
  93.         CALLDOS    Write                DOS call to write message
  94.             
  95.     
  96.     move.l    _stdout,d1            DOS output file handle         
  97.     move.l    #messb,d2            start of message          
  98.     move.l    d7,d3                size of message   
  99.         CALLDOS    Write                DOS call to write message
  100.        
  101.           
  102.     move.l    _stdout,d1            DOS output file handle         
  103.     move.l    #messi,d2            start of message          
  104.     move.l    #sizeofmessi,d3            size of message   
  105.         CALLDOS    Write                DOS call to write message
  106.                   
  107.     bra    vlab
  108.     
  109.     
  110.     
  111.                                         
  112. pass    
  113.     
  114.     move.l    d0,d6                    
  115.                 
  116. *free memory
  117.  
  118.     move.l    d6,d0
  119.  
  120.     move.l    #65538,d1
  121.  
  122.     CALLEXEC AllocMem
  123.     
  124.     tst.l    d0
  125.  
  126.     bne    passs
  127.     
  128.         
  129.     move.l    _stdout,d1            DOS output file handle         
  130.     move.l    #messj,d2            start of message          
  131.     move.l    #sizeofmessj,d3            size of message   
  132.         CALLDOS    Write                DOS call to write message
  133.                     
  134.     move.l    _stdout,d1            DOS output file handle         
  135.     move.l    #messb,d2            start of message          
  136.     move.l    d7,d3                size of message   
  137.         CALLDOS    Write                DOS call to write message
  138.     
  139.  
  140.         
  141.     move.l    _stdout,d1            DOS output file handle         
  142.     move.l    #messk,d2            start of message          
  143.     move.l    #sizeofmessk,d3            size of message   
  144.         CALLDOS    Write                DOS call to write message
  145.                             
  146.     bra    vlab                            
  147.  
  148. passs
  149.     move.l    d0,d5                    
  150.         
  151. *load in sound
  152.  
  153.  
  154.     move.l    d5,a0
  155.     move.l    #messb,d0
  156.             
  157.     CALLFU    LoadSound
  158.     tst.l    d0
  159.     beq    gofreemem
  160.     move.l    d0,d4                    
  161.     
  162.     
  163. *caluclate the period
  164.  
  165.     move.l    #3579545,d1
  166.  
  167.     divu    d4,d1
  168.     move.l    d1,d4    
  169.     
  170.     
  171.     
  172. *playsound
  173.  
  174. slab    move.l    d5,a0
  175.     move.l    d6,d0
  176.     move.l    #1,d1
  177.     move.l    d4,d2
  178.     move.l    #64,d3
  179.             
  180.     CALLFU    PlaySound
  181.     move.l    d0,d7                        
  182.     
  183.     
  184. *write choice message
  185.  
  186.          
  187.     move.l    _stdout,d1            DOS output file handle         
  188.     move.l    #messc,d2            start of message          
  189.     move.l    #sizeofmessc,d3            size of message   
  190.         CALLDOS    Write                DOS call to write message
  191.             
  192. *read choice
  193.  
  194.     move.l    _stdin,d1
  195.     move.l    #messd,d2
  196.     move.b    #2,d3
  197.     CALLDOS    Read            
  198.             
  199. *stop sound
  200.     move.l    d7,a0
  201.     CALLFU    StopSound
  202.      
  203.      
  204. *look at choice
  205.     
  206.     move.b    #'y',d0
  207.     cmp.b    messd,d0
  208.     beq    slab
  209.             
  210. *free memory
  211. gofreemem    
  212.     move.l    d5,a1
  213.     move.l    d6,d0    
  214.     CALLEXEC FreeMem
  215.  
  216.  
  217. *ask if wants to load new
  218.  
  219.         
  220. vlab    move.l    _stdout,d1            DOS output file handle         
  221.     move.l    #messe,d2            start of message          
  222.     move.l    #sizeofmesse,d3            size of message   
  223.         CALLDOS    Write                DOS call to write message
  224.             
  225. *get answer
  226.  
  227.  
  228.     move.l    _stdin,d1
  229.     move.l    #messf,d2
  230.     move.b    #2,d3
  231.     CALLDOS    Read            
  232.             
  233.             
  234. *look at answer            
  235.            
  236.     move.b    #'y',d0
  237.     cmp.b    messf,d0
  238.     beq    flab    
  239.                 
  240.  
  241. *print last message
  242.  
  243.        
  244.     move.l    _stdout,d1            DOS output file handle         
  245.     move.l    #messh,d2            start of message          
  246.     move.l    #sizeofmessh,d3            size of message   
  247.         CALLDOS    Write                DOS call to write message
  248.                     
  249.             
  250.             
  251. *close dos lib
  252. goclosedos
  253.     move.l    _DOSBase,a1
  254.     CALLEXEC CloseLibrary
  255.  
  256.  
  257. * finished so close future library
  258. goclosefu
  259.     move.l    _futurebase,a1
  260.     CALLEXEC CloseLibrary
  261.  
  262. gofast
  263.     moveq    #0,d0
  264.     rts
  265.  
  266.  
  267.  
  268.  
  269. *set up handle
  270. _stdout        ds.l    1            Set handle
  271. _stdin        ds.l    1
  272.  
  273.  
  274. * strings here
  275. funame        dc.b    'future.library',0    name of future lib
  276. dosname        dc.b    'dos.library',0
  277.  
  278. * variables here
  279. _futurebase    dc.l    0            for future library
  280. _DOSBase    dc.l    0
  281.  
  282. *messages
  283.  
  284. messa        dc.b    'Sound Player',10,'By Mark Retallack',10,'Plays IFF sound files using the Future Library',10
  285. sizeofmessa    equ    *-messa
  286.  
  287. messc        dc.b    'Play Again? (y/n): '
  288. sizeofmessc    equ    *-messc
  289.  
  290.  
  291. messb        ds.b    40
  292.  
  293. messd        ds.b    2
  294.  
  295. messe        dc.b    10,'Do you want to load a new sound (y/n): '
  296. sizeofmesse    equ    *-messe
  297.  
  298. messf        ds.b    2
  299.  
  300. messg        dc.b    10,'Enter Name Of File: '
  301. sizeofmessg    equ    *-messg
  302.  
  303. messh        dc.b    10,'Bye, Bye',10
  304. sizeofmessh    equ    *-messh
  305.  
  306. messi        dc.b    10,'File Dose Not Exist.',10
  307. sizeofmessi    equ    *-messi
  308.  
  309. messj        dc.b    10,'Cannot load file: '
  310. sizeofmessj    equ    *-messj
  311.  
  312. messk        dc.b    10,'Not an IFF file.',10
  313. sizeofmessk    equ    *-messk
  314.  
  315.  
  316.